package com.lawliet.example.model.system;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.core.GrantedAuthority;

import java.io.Serializable;
import java.util.Date;

@Data
@TableName("sys_permission")
@Schema(name = "SysPermission", description = "权限资源表")
public class SysPermission implements Serializable, GrantedAuthority {

    @Schema(description = "权限ID")
    @TableId(type = IdType.AUTO)
    private Long id;

    @Schema(description = "权限名称")
    private String name;

    @Schema(description = "权限类型（menu/button/api）")
    private String type;

    @Schema(description = "权限编码")
    private String permissionCode;

    @Schema(description = "资源路径")
    private String url;

    @Schema(description = "上级权限ID")
    private Long parentId;

    @Schema(description = "排序")
    private Integer sort;

    @Schema(description = "状态（1启用 0禁用）")
    private Integer status;

    @Schema(description = "创建人")
    @TableField(fill = FieldFill.INSERT)
    private Long createBy;

    @Schema(description = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @Schema(description = "更新人")
    @TableField(fill = FieldFill.UPDATE)
    private Long updateBy;

    @Schema(description = "更新时间")
    @TableField(fill = FieldFill.UPDATE)
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    @Schema(description = "逻辑删除")
    @TableLogic
    private Integer delFlag;

    @Override
    public String getAuthority() {
        return permissionCode;
    }
}
